home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / dbopen.z / dbopen
Encoding:
Text File  |  1998-10-20  |  19.2 KB  |  463 lines

  1.  
  2.  
  3.  
  4.      DDDDBBBBOOOOPPPPEEEENNNN((((3333))))        UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((JJJJaaaannnnuuuuaaaarrrryyyy 2222,,,, 1111999999994444))))        DDDDBBBBOOOOPPPPEEEENNNN((((3333))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.           dbopen - database access methods
  10.  
  11.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.           ####iiiinnnncccclllluuuuddddeeee <<<<ssssyyyyssss////ttttyyyyppppeeeessss....hhhh>>>>
  13.           ####iiiinnnncccclllluuuuddddeeee <<<<lllliiiimmmmiiiittttssss....hhhh>>>>
  14.           ####iiiinnnncccclllluuuuddddeeee <<<<ddddbbbb....hhhh>>>>
  15.  
  16.           DDDDBBBB ****
  17.           ddddbbbbooooppppeeeennnn((((ccccoooonnnnsssstttt cccchhhhaaaarrrr ****ffffiiiilllleeee,,,, iiiinnnntttt ffffllllaaaaggggssss,,,, iiiinnnntttt mmmmooooddddeeee,,,, DDDDBBBBTTTTYYYYPPPPEEEE ttttyyyyppppeeee,,,,
  18.                ccccoooonnnnsssstttt vvvvooooiiiidddd ****ooooppppeeeennnniiiinnnnffffoooo))));;;;
  19.  
  20.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  21.           _D_b_o_p_e_n is the library interface to database files.  The
  22.           supported file formats are btree, hashed and UNIX file
  23.           oriented.  The btree format is a representation of a sorted,
  24.           balanced tree structure.  The hashed format is an
  25.           extensible, dynamic hashing scheme.  The flat-file format is
  26.           a byte stream file with fixed or variable length records.
  27.           The formats and file format specific information are
  28.           described in detail in their respective manual pages
  29.           _b_t_r_e_e(3), _h_a_s_h(3) and _r_e_c_n_o(3).
  30.  
  31.           Dbopen opens _f_i_l_e for reading and/or writing.  Files never
  32.           intended to be preserved on disk may be created by setting
  33.           the file parameter to NULL.
  34.  
  35.           The _f_l_a_g_s and _m_o_d_e _a_r_g_u_m_e_n_t_s are as specified to the _o_p_e_n(2)
  36.           routine, however, only the O_CREAT, O_EXCL, O_EXLOCK,
  37.           O_NONBLOCK, O_RDONLY, O_RDWR, O_SHLOCK and O_TRUNC flags are
  38.           meaningful.  (Note, opening a database file O_WRONLY is not
  39.           possible.)
  40.  
  41.           The _t_y_p_e argument is of type DBTYPE (as defined in the
  42.           <db.h> include file) and may be set to DB_BTREE, DB_HASH or
  43.           DB_RECNO.
  44.  
  45.           The _o_p_e_n_i_n_f_o argument is a pointer to an access method
  46.           specific structure described in the access method's manual
  47.           page.  If _o_p_e_n_i_n_f_o is NULL, each access method will use
  48.           defaults appropriate for the system and the access method.
  49.  
  50.           _D_b_o_p_e_n returns a pointer to a DB structure on success and
  51.           NULL on error.  The DB structure is defined in the <db.h>
  52.           include file, and contains at least the following fields:
  53.  
  54.           typedef struct {
  55.                DBTYPE type;
  56.                int (*close)(const DB *db);
  57.                int (*del)(const DB *db, const DBT *key, u_int flags);
  58.                int (*fd)(const DB *db);
  59.                int (*get)(const DB *db, DBT *key, DBT *data, u_int flags);
  60.  
  61.  
  62.  
  63.      Page 1                                          (printed 4/30/98)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      DDDDBBBBOOOOPPPPEEEENNNN((((3333))))        UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((JJJJaaaannnnuuuuaaaarrrryyyy 2222,,,, 1111999999994444))))        DDDDBBBBOOOOPPPPEEEENNNN((((3333))))
  71.  
  72.  
  73.  
  74.                int (*put)(const DB *db, DBT *key, const DBT *data,
  75.                     u_int flags);
  76.                int (*sync)(const DB *db, u_int flags);
  77.                int (*seq)(const DB *db, DBT *key, DBT *data, u_int flags);
  78.           } DB;
  79.  
  80.           These elements describe a database type and a set of
  81.           functions performing various actions.  These functions take
  82.           a pointer to a structure as returned by _d_b_o_p_e_n, and
  83.           sometimes one or more pointers to key/data structures and a
  84.           flag value.
  85.  
  86.           type The type of the underlying access method (and file
  87.                format).
  88.  
  89.           close
  90.                A pointer to a routine to flush any cached information
  91.                to disk, free any allocated resources, and close the
  92.                underlying file(s).  Since key/data pairs may be cached
  93.                in memory, failing to sync the file with a _c_l_o_s_e or
  94.                _s_y_n_c function may result in inconsistent or lost
  95.                information.  _C_l_o_s_e routines return -1 on error
  96.                (setting _e_r_r_n_o) and 0 on success.
  97.  
  98.           del  A pointer to a routine to remove key/data pairs from
  99.                the database.
  100.  
  101.                The parameter _f_l_a_g may be set to the following value:
  102.  
  103.                R_CURSOR
  104.                     Delete the record referenced by the cursor.  The
  105.                     cursor must have previously been initialized.
  106.  
  107.                _D_e_l_e_t_e routines return -1 on error (setting _e_r_r_n_o), 0
  108.                on success, and 1 if the specified _k_e_y was not in the
  109.                file.
  110.  
  111.           fd   A pointer to a routine which returns a file descriptor
  112.                representative of the underlying database.  A file
  113.                descriptor referencing the same file will be returned
  114.                to all processes which call _d_b_o_p_e_n with the same _f_i_l_e
  115.                name.  This file descriptor may be safely used as an
  116.                argument to the _f_c_n_t_l(2) and _f_l_o_c_k(2) locking
  117.                functions.  The file descriptor is not necessarily
  118.                associated with any of the underlying files used by the
  119.                access method.  No file descriptor is available for in
  120.                memory databases.  _F_d routines return -1 on error
  121.                (setting _e_r_r_n_o), and the file descriptor on success.
  122.  
  123.           get  A pointer to a routine which is the interface for keyed
  124.                retrieval from the database.  The address and length of
  125.                the data associated with the specified _k_e_y are returned
  126.  
  127.  
  128.  
  129.      Page 2                                          (printed 4/30/98)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      DDDDBBBBOOOOPPPPEEEENNNN((((3333))))        UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((JJJJaaaannnnuuuuaaaarrrryyyy 2222,,,, 1111999999994444))))        DDDDBBBBOOOOPPPPEEEENNNN((((3333))))
  137.  
  138.  
  139.  
  140.                in the structure referenced by _d_a_t_a.  _G_e_t routines
  141.                return -1 on error (setting _e_r_r_n_o), 0 on success, and 1
  142.                if the _k_e_y was not in the file.
  143.  
  144.           put  A pointer to a routine to store key/data pairs in the
  145.                database.
  146.  
  147.                The parameter _f_l_a_g may be set to one of the following
  148.                values:
  149.  
  150.                R_CURSOR
  151.                     Replace the key/data pair referenced by the
  152.                     cursor.  The cursor must have previously been
  153.                     initialized.
  154.  
  155.                R_IAFTER
  156.                     Append the data immediately after the data
  157.                     referenced by _k_e_y, creating a new key/data pair.
  158.                     The record number of the appended key/data pair is
  159.                     returned in the _k_e_y structure.  (Applicable only
  160.                     to the DB_RECNO access method.)
  161.  
  162.                R_IBEFORE
  163.                     Insert the data immediately before the data
  164.                     referenced by _k_e_y, creating a new key/data pair.
  165.                     The record number of the inserted key/data pair is
  166.                     returned in the _k_e_y structure.  (Applicable only
  167.                     to the DB_RECNO access method.)
  168.  
  169.                R_NOOVERWRITE
  170.                     Enter the new key/data pair only if the key does
  171.                     not previously exist.
  172.  
  173.                R_SETCURSOR
  174.                     Store the key/data pair, setting or initializing
  175.                     the position of the cursor to reference it.
  176.                     (Applicable only to the DB_BTREE and DB_RECNO
  177.                     access methods.)
  178.  
  179.                R_SETCURSOR is available only for the DB_BTREE and
  180.                DB_RECNO access methods because it implies that the
  181.                keys have an inherent order which does not change.
  182.  
  183.                R_IAFTER and R_IBEFORE are available only for the
  184.                DB_RECNO access method because they each imply that the
  185.                access method is able to create new keys.  This is only
  186.                true if the keys are ordered and independent, record
  187.                numbers for example.
  188.  
  189.                The default behavior of the _p_u_t routines is to enter
  190.                the new key/data pair, replacing any previously
  191.                existing key.
  192.  
  193.  
  194.  
  195.      Page 3                                          (printed 4/30/98)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      DDDDBBBBOOOOPPPPEEEENNNN((((3333))))        UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((JJJJaaaannnnuuuuaaaarrrryyyy 2222,,,, 1111999999994444))))        DDDDBBBBOOOOPPPPEEEENNNN((((3333))))
  203.  
  204.  
  205.  
  206.                _P_u_t routines return -1 on error (setting _e_r_r_n_o), 0 on
  207.                success, and 1 if the R_NOOVERWRITE _f_l_a_g was set and
  208.                the key already exists in the file.
  209.  
  210.           seq  A pointer to a routine which is the interface for
  211.                sequential retrieval from the database.  The address
  212.                and length of the key are returned in the structure
  213.                referenced by _k_e_y, and the address and length of the
  214.                data are returned in the structure referenced by _d_a_t_a.
  215.  
  216.                Sequential key/data pair retrieval may begin at any
  217.                time, and the position of the ``cursor'' is not
  218.                affected by calls to the _d_e_l, _g_e_t, _p_u_t, or _s_y_n_c
  219.                routines.  Modifications to the database during a
  220.                sequential scan will be reflected in the scan, i.e.
  221.                records inserted behind the cursor will not be returned
  222.                while records inserted in front of the cursor will be
  223.                returned.
  224.  
  225.                The flag value mmmmuuuusssstttt be set to one of the following
  226.                values:
  227.  
  228.                R_CURSOR
  229.                     The data associated with the specified key is
  230.                     returned.  This differs from the _g_e_t routines in
  231.                     that it sets or initializes the cursor to the
  232.                     location of the key as well.  (Note, for the
  233.                     DB_BTREE access method, the returned key is not
  234.                     necessarily an exact match for the specified key.
  235.                     The returned key is the smallest key greater than
  236.                     or equal to the specified key, permitting partial
  237.                     key matches and range searches.)
  238.  
  239.                R_FIRST
  240.                     The first key/data pair of the database is
  241.                     returned, and the cursor is set or initialized to
  242.                     reference it.
  243.  
  244.                R_LAST
  245.                     The last key/data pair of the database is
  246.                     returned, and the cursor is set or initialized to
  247.                     reference it.  (Applicable only to the DB_BTREE
  248.                     and DB_RECNO access methods.)
  249.  
  250.                R_NEXT
  251.                     Retrieve the key/data pair immediately after the
  252.                     cursor.  If the cursor is not yet set, this is the
  253.                     same as the R_FIRST flag.
  254.  
  255.                R_PREV
  256.                     Retrieve the key/data pair immediately before the
  257.                     cursor.  If the cursor is not yet set, this is the
  258.  
  259.  
  260.  
  261.      Page 4                                          (printed 4/30/98)
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.      DDDDBBBBOOOOPPPPEEEENNNN((((3333))))        UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((JJJJaaaannnnuuuuaaaarrrryyyy 2222,,,, 1111999999994444))))        DDDDBBBBOOOOPPPPEEEENNNN((((3333))))
  269.  
  270.  
  271.  
  272.                     same as the R_LAST flag.  (Applicable only to the
  273.                     DB_BTREE and DB_RECNO access methods.)
  274.  
  275.                R_LAST and R_PREV are available only for the DB_BTREE
  276.                and DB_RECNO access methods because they each imply
  277.                that the keys have an inherent order which does not
  278.                change.
  279.  
  280.                _S_e_q routines return -1 on error (setting _e_r_r_n_o), 0 on
  281.                success and 1 if there are no key/data pairs less than
  282.                or greater than the specified or current key.  If the
  283.                DB_RECNO access method is being used, and if the
  284.                database file is a character special file and no
  285.                complete key/data pairs are currently available, the
  286.                _s_e_q routines return 2.
  287.  
  288.           sync A pointer to a routine to flush any cached information
  289.                to disk.  If the database is in memory only, the _s_y_n_c
  290.                routine has no effect and will always succeed.
  291.  
  292.                The flag value may be set to the following value:
  293.  
  294.                R_RECNOSYNC
  295.                     If the DB_RECNO access method is being used, this
  296.                     flag causes the sync routine to apply to the btree
  297.                     file which underlies the recno file, not the recno
  298.                     file itself.  (See the _b_f_n_a_m_e field of the
  299.                     _r_e_c_n_o(3) manual page for more information.)
  300.  
  301.                _S_y_n_c routines return -1 on error (setting _e_r_r_n_o) and 0
  302.                on success.
  303.  
  304.      KKKKEEEEYYYY////DDDDAAAATTTTAAAA PPPPAAAAIIIIRRRRSSSS
  305.           Access to all file types is based on key/data pairs.  Both
  306.           keys and data are represented by the following data
  307.           structure:
  308.  
  309.           typedef struct {
  310.                void *data;
  311.                size_t size;
  312.           } DBT;
  313.  
  314.           The elements of the DBT structure are defined as follows:
  315.  
  316.           data A pointer to a byte string.
  317.  
  318.           size The length of the byte string.
  319.  
  320.           Key and data byte strings may reference strings of
  321.           essentially unlimited length although any two of them must
  322.           fit into available memory at the same time.  It should be
  323.           noted that the access methods provide no guarantees about
  324.  
  325.  
  326.  
  327.      Page 5                                          (printed 4/30/98)
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.      DDDDBBBBOOOOPPPPEEEENNNN((((3333))))        UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((JJJJaaaannnnuuuuaaaarrrryyyy 2222,,,, 1111999999994444))))        DDDDBBBBOOOOPPPPEEEENNNN((((3333))))
  335.  
  336.  
  337.  
  338.           byte string alignment.
  339.  
  340.      EEEERRRRRRRROOOORRRRSSSS
  341.           The _d_b_o_p_e_n routine may fail and set _e_r_r_n_o for any of the
  342.           errors specified for the library routines _o_p_e_n(2) and
  343.           _m_a_l_l_o_c(3) or the following:
  344.  
  345.           [EFTYPE]
  346.                A file is incorrectly formatted.
  347.  
  348.           [EINVAL]
  349.                A parameter has been specified (hash function, pad byte
  350.                etc.) that is incompatible with the current file
  351.                specification or which is not meaningful for the
  352.                function (for example, use of the cursor without prior
  353.                initialization) or there is a mismatch between the
  354.                version number of file and the software.
  355.  
  356.           The _c_l_o_s_e routines may fail and set _e_r_r_n_o for any of the
  357.           errors specified for the library routines _c_l_o_s_e(2), _r_e_a_d(2),
  358.           _w_r_i_t_e(2), _f_r_e_e(3), or _f_s_y_n_c(2).
  359.  
  360.           The _d_e_l, _g_e_t, _p_u_t and _s_e_q routines may fail and set _e_r_r_n_o
  361.           for any of the errors specified for the library routines
  362.           _r_e_a_d(2), _w_r_i_t_e(2), _f_r_e_e(3) or _m_a_l_l_o_c(3).
  363.  
  364.           The _f_d routines will fail and set _e_r_r_n_o to ENOENT for in
  365.           memory databases.
  366.  
  367.           The _s_y_n_c routines may fail and set _e_r_r_n_o for any of the
  368.           errors specified for the library routine _f_s_y_n_c(2).
  369.  
  370.      SSSSEEEEEEEE AAAALLLLSSSSOOOO
  371.           _b_t_r_e_e(3), _h_a_s_h(3), _m_p_o_o_l(3), _r_e_c_n_o(3)
  372.  
  373.           _L_I_B_T_P: _P_o_r_t_a_b_l_e, _M_o_d_u_l_a_r _T_r_a_n_s_a_c_t_i_o_n_s _f_o_r _U_N_I_X, Margo
  374.           Seltzer, Michael Olson, USENIX proceedings, Winter 1992.
  375.  
  376.      BBBBUUUUGGGGSSSS
  377.           The typedef DBT is a mnemonic for ``data base thang'', and
  378.           was used because noone could think of a reasonable name that
  379.           wasn't already used.
  380.  
  381.           The file descriptor interface is a kluge and will be deleted
  382.           in a future version of the interface.
  383.  
  384.           None of the access methods provide any form of concurrent
  385.           access, locking, or transactions.
  386.  
  387.           This version of berkeley db (1.85) is free software which is
  388.           not developed nor maintained by SGI.  It is known to have
  389.           some bugs that are unlikely to get fixed (See NOTES below)
  390.  
  391.  
  392.  
  393.      Page 6                                          (printed 4/30/98)
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.      DDDDBBBBOOOOPPPPEEEENNNN((((3333))))        UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((JJJJaaaannnnuuuuaaaarrrryyyy 2222,,,, 1111999999994444))))        DDDDBBBBOOOOPPPPEEEENNNN((((3333))))
  401.  
  402.  
  403.  
  404.           in particular, certain cursor and certain deletion/overwrite
  405.           operations are known to have problems, up to corrupting
  406.           databases, and should be avoided according to
  407.           http://www.sleepycat.com/db.185.html.  See _h_a_s_h(3), and
  408.           _b_t_r_e_e(3) for details.
  409.  
  410.  
  411.      NNNNOOOOTTTTEEEESSSS
  412.           The default hash function in this version of db is the
  413.           Fowler/Vo/Noll hash which gives better distributions (less
  414.           collisions) on average than the publicly released version.
  415.  
  416.           This version of berkeley db is 1.85.  A newer, enhanced
  417.           version db-2.x requires licensing. Check out
  418.           http://www.sleepycat.com/ for details.
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.      Page 7                                          (printed 4/30/98)
  460.  
  461.  
  462.  
  463.